package com.situ.day2;

import org.junit.Test;

import java.util.AbstractCollection;
import java.util.Scanner;

public class Demo {

    @Test
    public void test1() {
        //双目运算符：=、+
        //单目运算符：++、--
        int num1 = 3;
        int num2 = 5;
        int result1 = num1 + num2;
        //数字和字符串可以使用+拼接在一起，形成一个字符串
        System.out.println("result1: " + result1);
        int result2 = num1 - num2;
        System.out.println("result2: " + result2);
        System.out.println(num1 * num2);
        System.out.println(num1 / num2);//0
        System.out.println(num1 % num2);//3
    }

    @Test
    public void test2() {
        //1、单独使用的时候，++、--在前后是没有差别的
        //2、被使用的时候，在前后是有差别的
        int i = 0;
        i = i + 1;
        System.out.println(i);//1
        i++;//i = i + 1
        i--;//i = i - 1;
        System.out.println(i);//1
        ++i;//i = i + 1;
        --i;//i = i - 1;
        System.out.println(i);//1
        System.out.println(i++);//1
        System.out.println(i);//2
        System.out.println(++i);//3
    }

    //比较运算符：>   <    >=     <=    !=
    @Test
    public void test3() {
        int num1 = 3;
        int num2 = 5;
        //比较运算符的结果是一个boolean类型
        boolean bool = num1 > num2;
        System.out.println(bool);//false
        System.out.println(num1 < num2);//true
        System.out.println(num1 <= num2);//true
        System.out.println(num1 != num2);//true
    }

    // 逻辑运算符：&&      ||      ！    运算结果也是boolean类型
    // &&：两边的结果都是true，结果才是true
    // ||：两边只要有一个是true，结果就是true
    @Test
    public void test5() {
        int score1 = 67;
        int score2 = 394;
        boolean bool1 = (score1 >= 60) && (score2 >= 400);
        System.out.println(bool1);//false
        boolean bool2 = (score1 >= 60) || (score2 >= 400);
        System.out.println(bool2);//true
    }

    @Test
    public void test6() {
        int num1 = 3;
        int num2 = 5;
        if (num1 < num2) {
            System.out.println("num1<num2");
        } else {
            System.out.println("num1>=num2");
        }
    }

    @Test
    public void test7() {
        int num1 = 3;
        int num2 = 5;
        int max = 0;
        if (num1 > num2) {
            max = num1;
        } else if (num1 < num2) {
            max = num2;
        } else {
            System.out.println("num1==num2");
        }
        System.out.println(max);
    }

    @Test
    public void test87() {
        int num1 = 5;
        int num2 = 5;
        int max = 0;
        if (num1 >= num2) {
            max = num1;
        } else {
            max = num2;
        }
        System.out.println(max);
    }

    @Test
    public void test555() {
        int num1 = 15;
        int num2 = 5;
        //三目元算符
        int max = num1 >= num2 ? num1 : num2;
        System.out.println(max);
    }


//    >=90   <=100      优秀
//    >=80    <90       良好
//    >=70    <80       一般
//    >=60    <70      及格
//    <60              不及格
    @Test
    public void test55() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入成绩：");
        int score = scanner.nextInt();
        //int score = 77;
        if (score >= 90 && score <= 100) {
            System.out.println("优秀");
        } else if (score >= 80 && score < 90) {
            System.out.println("良好");
        } else if (score >= 70 && score < 80) {
            System.out.println("一般");
        } else if (score >= 60 && score < 70) {
            System.out.println("及格");
        } else {
            System.out.println("不及格");
        }
    }

    @Test
    public void test456() {
        int count = 1;
        while (count <= 5) {
            System.out.println("HelloWorld");
            count++;
        }
    }

    @Test
    public void test5535() {
        // i,j,k
        for (int i = 1; i <= 5; i++) {
            System.out.println("HelloWorld");
        }
    }

    //1、累加思想（1+2+3+... + 100）
    @Test
    public void test444() {
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            //System.out.println(i);
            sum = sum + i;
            //System.out.println("sum: " + sum);
        }
        System.out.println("sum: " + sum);
    }

    //2、统计思想，数一下符合条件的有多少个（计算1-100以内7的倍数的个数）
    @Test
    public void test66() {
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 7 == 0) {
                System.out.println(i);
                count++;
            }
        }
        System.out.println("count: " + count);
    }


//  continue、break：
//  continue：跳出本次循环，继续下一次循环
//  break：跳出离他最近的那层循环
    @Test
    public void test556() {
        for (int i = 1; i <= 5; i++) {
            if (i == 3) {
                continue;
            }
            System.out.println(i);
        }
    }

    @Test
    public void test557() {
        for (int i = 1; i <= 5; i++) {
            if (i == 3) {
                break;
            }
            System.out.println(i);
        }
    }

    @Test
    public void test558() {
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= 5 ; j++) {
                if (j == 3) {
                    break;
                }
                System.out.println("j: " + j);
            }
            System.out.println("i: " + i);
        }
    }

    @Test
    public void test5563() {
        //无限循环、死循环
        while (true) {
            System.out.println("Demo.test5563");
        }
        //Unreachable statement
        /*for (;;) {

        }*/
    }

    @Test
    public void test333() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入年份：");
        int year = scanner.nextInt();
        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 ==  0)){
            System.out.println(year + "是闰年");
        } else {
            System.out.println(year + "不是闰年");
        }
    }

    @Test
    public void test626() {
        int num1 = 3;
        int num2 = 5;

        int temp = num1;
        num1 = num2;
        num2 = temp;

        System.out.println("num1: " + num1);//5
        System.out.println("num2: " + num2);//3
    }
}
